从函数本身内部的按钮调用 jQuery 函数
calling a jquery function from a button which inside the function itself
这是调用 webservice 以返回 json 的代码
$('#page_job_list_pages').live('pageshow',function(){
try {
$.ajax({
url: "http://domain.com/json/" + encodeURIComponent(tid),
type: 'get',
dataType: 'json',
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('page_job_list_pages - failed to retrieve pages');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
$("#page_job_list_pages_list").html("");
$.each(data.nodes,function (node_index,node_value) {
console.log(JSON.stringify(node_value));
if(node_index != 0) {
var companyName = node_value.node.field_basic_info.match("Company:(.*)date");
$("#page_job_list_pages_list").append($("<li></li>",{"html":"<a href='#node_view' id='" + node_value.node.Nid + "' class='page_job_list_pages_list_title'>" + companyName[1] + "</a>"}));
}
});
$("#page_job_list_pages_list").listview("destroy").listview();
$("#page_job_list_pages_list").append('<a onclick="()" data-role="button" data-theme="a">TEST</a>');
}
});
}
catch (error) { alert("page_job_list_pages_list - " + error); }
});
this line is a button
$("#page_job_list_pages_list").append('<a onclick="()" data-role="button" data-theme="a">TEST</a>');
我想调用 jquery 函数再次查询 json。
怎么做?
我已经将您的查询包装在一个函数中。我假设这是你想要的。我还在按钮的单击处理程序中添加了调用以再次查询。
注意:从 jQuery 1.7 开始,.live()
方法已被弃用。使用 .on()
附加事件处理程序。使用旧版本的 jQuery 的用户应优先使用 .delegate() 而不是 .live()。(来源:http://api.jquery.com/live/)
$('#page_job_list_pages').live('pageshow',function(){
queryJSON();
});
function queryJSON(){
try {
$.ajax({
url: "http://domain.com/json/" + encodeURIComponent(tid),
type: 'get',
dataType: 'json',
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('page_job_list_pages - failed to retrieve pages');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
$("#page_job_list_pages_list").html("");
$.each(data.nodes,function (node_index,node_value) {
console.log(JSON.stringify(node_value));
if(node_index != 0) {
var companyName = node_value.node.field_basic_info.match("Company:(.*)date");
$("#page_job_list_pages_list").append($("<li></li>",{"html":"<a href='#node_view' id='" + node_value.node.Nid + "' class='page_job_list_pages_list_title'>" + companyName[1] + "</a>"}));
}
});
$("#page_job_list_pages_list").listview("destroy").listview();
$("#page_job_list_pages_list").append('<a onclick="queryJSON();" data-role="button" data-theme="a">TEST</a>');
}
});
}
catch (error) { alert("page_job_list_pages_list - " + error); }
}
this line is a button
$("#page_job_list_pages_list").append('<a onclick="queryJSON();" data-role="button" data-theme="a">TEST</a>');
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- JavaScript按钮/输入/函数,字符串反转
- 代码背后调用一个JavaScript函数的按钮点击-C#
- 在按钮上调用Javascript函数
- 如果函数返回True,则显示Javascript按钮
- HTML 按钮点击函数无法使用 jQuery 变量作为参数
- 提交按钮通过JQuery和JavaScript函数所做的更改不会持续
- JavaScript-onClick将按钮ID或单击按钮的文本传递给函数
- 如何从reactjs中的按钮向函数传递props
- 如何在javascript中添加带有回调函数的按钮点击事件作为window.conf
- 获取javascript函数中的按钮名称
- 使用函数按钮调用 ajaxform
- if语句禁用了我的jquery函数/按钮
- 如何防止默认操作函数按钮(F4,F5等)在Angular js中
- 定义函数按钮javascript
- Javascript函数按钮
- 在另一个页面上进行javascript函数/按钮点击事件调用
- 当我点击“提交”时,如何调用Javascript函数?按钮
- 在asp上使用Ajax Javascript调用c#函数:按钮点击,不工作
- 调用一个php函数按钮点击jquery - Astra Api