Javascript 为什么我能';是否在所需元素中附加一些html?
我希望有人能帮我一把,我一直在尝试通过插入一些代码。post使用jquery一切似乎都很好,但响应数据没有插入conhere div htmlJavascript 为什么我能';是否在所需元素中附加一些html?,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我希望有人能帮我一把,我一直在尝试通过插入一些代码。post使用jquery一切似乎都很好,但响应数据没有插入conhere div html 此代码存在两个问题: $(this).parents(".ui-block-a").find(".conhere")... 第一个问题是.conhere元素在.ui-block-a中不存在。它存在于.ui-block-b中。(并且.ui-block-a和.ui-block-b都在.ui-grid-a中)find只查看调用它的集合中元素的后代元素 第二个
此代码存在两个问题:
$(this).parents(".ui-block-a").find(".conhere")...
第一个问题是.conhere
元素在.ui-block-a
中不存在。它存在于.ui-block-b
中。(并且.ui-block-a
和.ui-block-b
都在.ui-grid-a
中)find
只查看调用它的集合中元素的后代元素
第二个问题是,此
不再是调用$.post
之外的内容。所以我们想把它捕获到一个变量中
最后,在本例中,我将使用,而不是:
结合以上内容:
$(document).on("change", ".checkpro", function (event, ui) {
var $elm = $(this), // <== Remember $(this)
checkedpro = $elm.is(':checked') ? 1 : 0;
if (checkedpro == 1) {
var variable = $elm.val().split("##");
$.post("product.php", h {
row: contenedor[0],
mul: variable[1],
can: variable[2],
pri: variable[3],
id: variable[4]
},
function (data) {
// v-------------------------------- use it, and note 'closest'
$elm.closest(".ui-grid-a").find(".conhere").empty().append(data).trigger('create');
});
} // <== This } was also missing
else {
$elm.closest(".ui-grid-a").find(".conhere").empty();
}
$(document).on(“change”,“checkpro”,函数(事件,用户界面){
var$elm=$(这个),//.parents(“.ui-block-a”)
应该是。parents(“.ui-grid-a”)
很抱歉,因为我使用的是jquery mobile,所以它是$(“#notayuda”),但为了让它更干净,我改成了document,忘了擦除“@奥马尔:是的,我已经删除了。我忘了jQuery可以可靠地使更改冒泡。旁注:除非你附加了一个jQM小部件,否则你不需要.trigger(“create”)
。使用jQuery mobile,我需要.trigger(“create”)来正确呈现页面。我使用的是“.ui-grid-a”仍然没有。product.php加载但未插入到。conhere@Atondo:还有一个问题,还有一个基本的语法错误。更新了。抱歉,这是我第一次发布问题,我的实际代码有点棘手。我试图简化它,但我的复制粘贴技能不好。谢谢,现在我用了var$elm=$(此项);而不是“,”
$(this).parents(".ui-block-a").find(".conhere")...
$(this).closest(".ui-grid-a").find(".ui-block-b .conhere")...
// or
$(this).closest(".ui-grid-a").find(".conhere")...
$(document).on("change", ".checkpro", function (event, ui) {
var $elm = $(this), // <== Remember $(this)
checkedpro = $elm.is(':checked') ? 1 : 0;
if (checkedpro == 1) {
var variable = $elm.val().split("##");
$.post("product.php", h {
row: contenedor[0],
mul: variable[1],
can: variable[2],
pri: variable[3],
id: variable[4]
},
function (data) {
// v-------------------------------- use it, and note 'closest'
$elm.closest(".ui-grid-a").find(".conhere").empty().append(data).trigger('create');
});
} // <== This } was also missing
else {
$elm.closest(".ui-grid-a").find(".conhere").empty();
}