MalcKear
千年狐狸
千年狐狸
  • UID35386
  • 注册日期2011-03-05
  • 最后登录2020-03-02
  • 发帖数1348
  • 经验131枚
  • 威望0点
  • 贡献值16点
  • 好评度10点
  • 社区居民
  • 忠实会员
阅读:1653回复:2

如何通过GM脚本,自动选择单选框"no" ?

楼主#
更多 发布于:2016-06-23 12:30
<tr class="showClass">
<td class="td02" height="30px">
<div>
<input name="h2aholderradio" onclick="jQuery('#healthInform2aholder').show()" value="yes" type="radio">是
</div>
<div>
<input name="h2aholderradio" onclick="jQuery('#healthInform2aholder').hide();selectSameRadio(this);" value="no" type="radio">否
</div>
</td>
<td class="td02">
<div>
<input disabled="disabled" name="h2ainsurantradio" onclick="jQuery('#healthInform2ainsurant').show()" value="yes" type="radio">是
</div>
<div>
<input disabled="disabled" name="h2ainsurantradio" onclick="jQuery('#healthInform2ainsurant').hide();selectSameRadio(this);" value="no" type="radio">否
</div>
</td>
</tr>
<tr class="showClass">
<td class="td02" height="30px">
<div>
<input name="h2bholderradio" onclick="jQuery('#healthInform2bholder').show()" value="yes" type="radio">是
</div>
<div>
<input name="h2bholderradio" onclick="jQuery('#healthInform2bholder').hide()" value="no" type="radio">否
</div>
</td>
<td class="td02">
<div>
<input disabled="disabled" name="h2binsurantradio" onclick="jQuery('#healthInform2binsurant').show()" value="yes" type="radio">是
</div>
<div>
<input disabled="disabled" name="h2binsurantradio" onclick="jQuery('#healthInform2binsurant').hide()" value="no" type="radio">否
</div>
</td>
</tr>
试过1:
if(radio=document.evaluate('//input[@type="radio" and @onclick="setBank(9,0,1)"]',document,null,9,null).singleNodeValue) {
radio.checked = true;
}
试过2:
if(radio=document.evaluate('//input[@type="radio" and @value="no"]',document,null,9,null).singleNodeValue) {
radio.checked=true;
}
试过3:
var checkbox = document.querySelector('input[type="radio"][value="no"]')
if (checkbox) {
checkbox.checked = true;
}
试过4:http://userscripts-mirror.org/scripts/review/36893


都搞不定。。。

最新喜欢:

infinityinfini...
taoww
非常火狐
非常火狐
  • UID39284
  • 注册日期2013-03-18
  • 最后登录2024-03-26
  • 发帖数621
  • 经验569枚
  • 威望0点
  • 贡献值110点
  • 好评度99点
1楼#
发布于:2016-06-23 15:00
123都只会设置单个单选框的
4虽然可以设置多个,还要靠用户脚本命令来启用。但是由于它太老了,在meta段没有写@grant来申请GM的API使用,所以也不会有用

给4的开头加上
// @grant          GM_getValue
// @grant          GM_setValue
// @grant          GM_registerMenuCommand

或者你直接拿4里面的setToNo的代码来调用
function setToNo() {
var i, radios = document.evaluate("//input[@type='radio' and @value='no']", document, null, 6, null);
for(i=0; i<radios.snapshotLength; i++) {
radios.snapshotItem(i).checked = true;
}
}
MalcKear
千年狐狸
千年狐狸
  • UID35386
  • 注册日期2011-03-05
  • 最后登录2020-03-02
  • 发帖数1348
  • 经验131枚
  • 威望0点
  • 贡献值16点
  • 好评度10点
  • 社区居民
  • 忠实会员
2楼#
发布于:2016-06-23 16:16
taoww:123都只会设置单个单选框的
4虽然可以设置多个,还要靠用户脚本命令来启用。但是由于它太老了,在meta段没有写@grant来申请GM的API使用,所以也不会有用

给4的开头加上
// @grant          GM_get...
回到原帖
感谢2L的解答,可能公司的系统比较复杂,1-4不管是单个还是多个复选框都无效。
4提取的也过不了~
提供下贴吧@柏拉图样图森破
Array.prototype.forEach.call(document.querySelectorAll('input[value="no"]'),function(i){i.checked=true;});
以上可以通过~
游客

返回顶部