Jquery 添加响应状态
<form>
<input type="checkbox" id="m_q" name="m_q" value="271">Name</input><div name="status"></div>
<input type="checkbox" id="m_q" name="m_q" value="271">Age</input><div name="status"></div>
<input type="checkbox" id="m_q" name="m_q" value="271">ID</input><div name="status"></div>
<input type="checkbox" id="m_q" name="m_q" value="271">Emp no</input><div name="status"></div>
<input type="button" value="save" onclick="save" />
</form>
<script>
function save()
{
$.post("/det/save_details/",snddata,
function(data){
if(data == 0 ){
alert('data added');
//How to disable the checkbox field and in the div say data added
},"json");
}
</script>
在上面的代码中,在 onselect() 从服务器获取响应后,如何在状态 div 中仅针对选定的复选框说“已添加数据”
<form>
<input type="checkbox" id="m_q" name="m_q" value="271">Name</input><div name="status"></div>
<input type="checkbox" id="m_q" name="m_q" value="271">Age</input><div name="status"></div>
<input type="checkbox" id="m_q" name="m_q" value="271">ID</input><div name="status"></div>
<input type="checkbox" id="m_q" name="m_q" value="271">Emp no</input><div name="status"></div>
<input type="button" value="save" onclick="save" />
</form>
<script>
function save()
{
$.post("/det/save_details/",snddata,
function(data){
if(data == 0 ){
alert('data added');
//How to disable the checkbox field and in the div say data added
},"json");
}
</script>
In the above code after getting the response from the server onselect() ,how to say "data added" in the status div for selected checkbox only
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Haim 的代码有效,但我认为他问的是如何根据选中的复选框和他提供的 html 将 html 添加到 div,该 html 没有 div 的特定 ID,所以这里是一些 jquery 代码适用于您提供的 html。它会抓取选中的框并禁用它们,然后抓取下一个名称=状态的同级 div 以将 html 文本添加到其中。
您可以看到 jsFiddle 页面,其中包含 HTML 示例(没有 Ajax 部分,只需在单击中完成)而是按钮的事件)。
@Haim's code works but I think he was asking how to add the html to the div based on which checkbox was checked and based on the html he provided, which doesn't have specific ID's for the divs, so here is some jquery code that works with the html you have provided. It grabs the checked boxes and disables them, then grabs the next sibling div with name=status to add the html text to it.
You can see a jsFiddle page with an example with your HTML (without the Ajax part and just done in the click event of the button instead).
要在 div 中显示,请使用 html() 函数
禁用使用 attr()
to display in div use html() func
to disable use attr()