我在我的html页面中有一个对象,
基于注释进行编辑:这是我的XML
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Item>
<Property_Cat_ID>1</Property_Cat_ID>
<Property_Cat_Name>Buy</Property_Cat_Name>
</Item>
<Item>
<Property_Cat_ID>2</Property_Cat_ID>
<Property_Cat_Name>Rent</Property_Cat_Name>
</Item>
</Root>这是HTML
<div class="ddpan01">
<div class="ddBoxHold">
<div class="ddBox">
<asp:TextBox ID="txtCat" runat="server" Value="Buy" ReadOnly="true"></asp:TextBox>
<asp:HiddenField ID="hdnTypeId" runat="server" Value="0" />
<span></span>
</div>
<div class="ddList">
<div class="ddListData">
<ul>
</ul>
</div>
</div>
</div>
</div>在DOM上准备好页面脚本。
$("div.ddpan01 div.ddBoxHold").find("div.ddList").find("div.ddListData ul li").click(function () {
alert('click');
getValues(0); // function which does dynamic value assigning work to all my fields
})
$.ajax({
type: "GET",
url: "/Admin/Includes/XML/PropertyCategory.xml",
dataType: "xml",
success: function (xml) {
var count = 1;
$(xml).find('Item').each(function () {
var id = $(this).find('Property_Cat_ID').text();
var name = $(this).find('Property_Cat_Name').text();
if (count == 1) {
$("div.tabdpan02").find("div.ddpan div.ddpan01 div.ddBoxHold div.ddBox input:first").val(name);
$("div.tabdpan02").find("div.ddpan div.ddpan01 div.ddBoxHold div.ddBox input:last").val(id);
}
$("<li id=" + id + "></li>").html(name).appendTo($("div.tabdpan02").find("div.ddpan div.ddpan01 div.ddBoxHold div.ddList div.ddListData ul"));
count++
});
}
});不,在页面的my head部分,我们已经调用了一个名为effect.js的文件,它也有一个单击事件。
下面的函数在effects.js文件中
$(".ddListData ul li").live('click', function () {
var htmlStr = $(this).html();
var hId = $(this).attr('id');
$(this).parent('ul').parent('div').parent('div').prev('.ddBox').find('input:first').val(htmlStr);
$(this).parent('ul').parent('div').parent('div').prev('.ddBox').find('input:last').val(hId);
$(this).parent('ul').parent('div').parent('div').hide(0);
})我的问题是,哪个函数将首先执行,以及在执行effect.js单击函数后,如何才能将getValues(0);作为单击事件调用。
我希望我能够解释我的问题,在这里写和解释它是太大和复杂。
发布于 2012-01-05 20:00:58
如果需要实现此行为,则必须使用自定义事件。将ajax数据加载事件包装在自定义事件中,然后从单击事件触发该事件,反之亦然。
作为参考,在这个post上有一个完整的实现。
https://stackoverflow.com/questions/8739718
复制相似问题