简体   繁体   English

取消选择jQuery链接按钮

[英]Deselect jQuery link button

I have a problem with link buttons at jQuery. 我在jQuery的链接按钮有问题。 The most forum entries I found at the web with searching for "jQuery link button deselect" handle about form buttons or checkboxes and not link buttons. 我在网上找到的大多数论坛条目,搜索“jQuery链接按钮取消选择”处理表单按钮或复选框而不是链接按钮。 So I hope someone here can help me :-). 所以我希望有人可以帮助我:-)。

Problem description: I have some static link bottons at my web page and with clicking on it I call a javascript function and change the text at the buttons. 问题描述:我的网页上有一些静态链接底部,点击它我调用javascript函数并更改按钮上的文本。 Now my problem is that the buttons are still selected after changing the text and this is what not should be. 现在我的问题是在更改文本后仍然选择按钮,这是不应该的。

index.html: index.html的:

<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  <script src="jquery-mobile/jquery.mobile-1.0.min.js"  type="text/javascript"></script>
  <script src="basic.js" type="text/javascript"></script>
</head>
<body>
...
<a href="#" data-role="button" onmouseup="nextStep(1)" id="button1">Example1</a>
<a href="#" data-role="button" onmouseup="nextStep(2)" id="button2">Example2</a>
<a href="#" data-role="button" onmouseup="nextStep(3)" id="button3">Example3</a>
...
</body>

basic.js basic.js

function nextStep(buttonIndex){
  $("#button1 .ui-btn-text").text("Example4");
  $("#button2 .ui-btn-text").text("Example5");
  $("#button3 .ui-btn-text").text("Example6");
}

The code above is an example what I am doing. 上面的代码就是我正在做的一个例子。 How described at the beginning after setting the new text the button is still selected. 如何在设置新文本后开始描述仍然选择按钮。 Does anybody know a solution to deselect the button? 有人知道取消选择按钮的解决方案吗?

Picture of selected button: http://up.picr.de/12133494ev.png 所选按钮的图片: http//up.picr.de/12133494ev.png

Thanks for helping :-). 谢谢你的帮助:-)。

Thomas 托马斯

------------------------- -------------------------


Thank you for your fast response. 感谢您的快速回复。 I tried the proposal 我试过这个提议

function nextStep(buttonIndex){
  $("#button1 .ui-btn-text").text("Example4").removeClass('ui-btn-active');
  $("#button2 .ui-btn-text").text("Example5").removeClass('ui-btn-active');
  $("#button3 .ui-btn-text").text("Example6").removeClass('ui-btn-active');
}

Unfortunately, it does not work as expectect. 不幸的是,它并不像预期的那样有效。 More precisely I can not see any changes in behavior. 更确切地说,我看不到行为的任何变化。

Note, it's possible your page has other elements going on that would cause such a behavior. 请注意,您的页面可能还有其他元素会导致此类行为。

The buttons are part of a page with other elements (headline and table) where I change contents via javascript. 这些按钮是包含其他元素(标题和表格)的页面的一部分,我通过javascript更改内容。 But for me it is not clear how this should influence the behavior of the buttons. 但对我而言,目前尚不清楚这应该如何影响按钮的行为。

Examples: 例子:

var table = document.getElementById('solution');
var cell = table.rows[1].cells[1];
cell = table.rows[2].cells[1];
cell.firstChild.data = "";
cell = table.rows[3].cells[1];
cell.firstChild.data = "";
cell = table.rows[4].cells[1];
cell.firstChild.data = "";
...

or 要么

$("#headline").empty();
headlineOutput = "Buttons";
$("#headline").append(headlineOutput);

Any suggestions or hints? 有什么建议或提示吗?

Thank you. 谢谢。

------------------------- -------------------------


function nextStep(buttonIndex){
  $("#button1 .ui-btn-text").text("Example4").blur();
  $("#button2 .ui-btn-text").text("Example5").blur();
  $("#button3 .ui-btn-text").text("Example6").blur();
}

This proposal does also no changes in behavior :-(. 这个提议也没有改变行为:-(。

I am missing something like the Qt functions "setCheckable(false) and setFocusPolicy(Qt::NoFocus)" ;-). 我遗漏了Qt函数“setCheckable(false)和setFocusPolicy(Qt :: NoFocus)”;-)。

Thanks for helping. 谢谢你的帮助。

Try this: 尝试这个:

function nextStep(buttonIndex){
  $("#button1 .ui-btn-text").text("Example4").blur();
  $("#button2 .ui-btn-text").text("Example5").blur();
  $("#button3 .ui-btn-text").text("Example6").blur();
}

If that does not work, try this: 如果这不起作用,试试这个:

function nextStep(buttonIndex){
  $("#button1 .ui-btn-text").text("Example4").removeClass('ui-btn-active');
  $("#button2 .ui-btn-text").text("Example5").removeClass('ui-btn-active');
  $("#button3 .ui-btn-text").text("Example6").removeClass('ui-btn-active');
}

I created a fiddle here: http://jsfiddle.net/japanick/Lc9rp/ 我在这里创造了一个小提琴: http//jsfiddle.net/japanick/Lc9rp/

It works as expected, starting with the code you have. 从您拥有的代码开始,它按预期工作。 Can you give it a try and see if it's working how you expected. 你可以尝试一下,看看它是否按预期工作。 Note, it's possible your page has other elements going on that would cause such a behavior. 请注意,您的页面可能还有其他元素会导致此类行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM