我有下面的代码。
当我从 #searchbutton 触发 #tempbutton (以对象作为参数)时,它工作正常。但是当我从#myid 做同样的事情时,它不会触发。
有什么想法我可能做错了吗?谢谢
这是我的代码。请假设从某处调用 getAjax。只是我不得不剥离大量代码以使其简短/可读。但这部分绝对有效。:)
var onclickmyid = function(event, parameters) {
event.preventDefault();
console.log(event.data); //works. it displays the listlength passed
$("#tempbutton").trigger("click", [ "test" ]); // works but obviously, it won't be an object
//$("#tempbutton").trigger("click", [{ name:"test" }]); // doesn't work although it' the same as the one below
};
var onclicktempbutton = function(event, parameters) { console.log(parameters); }
var onclicksearchbutton = function(event) {
event.preventDefault();
$("#tempbutton").trigger("click", [{ name:"test" }]); //works
};
$(document).on("click", "#tempbutton", onclicktempbutton);
$(document).on("click", "#searchbutton", onclicksearchbutton);
function getAjax() {
$.ajax({
url: my-url-here
, cache: false
, dataType: "json"
, data: {}
, success: function(data, status) {
displayTopicList({ data:data });
}
});
}
function displayTopicList(parameters) {
$.each(parameters.data, function(index, option) {
$("#mylinks").append($("<a></a><br />").attr("id", "myid"+option.id).attr("href", "javascript:void(0)");
});
$(document).on("click", "[id^=myid]", { listlength:parameters.data.length }, onclickmyid);
}