2
<div class="form-component form-checkbox     ">
<input id="post-ad_feature_NOT_PROMOTED_selected" type="checkbox" name="features['NOT_PROMOTED'].selected" value="true"   data-siblings="#post-ad_feature_URGENT_selected, #post-ad_feature_FEATURED_selected, #post-ad_feature_SPOTLIGHT_selected, #post-ad_feature_WEBSITE_URL_selected, #post-ad_feature_NOT_PROMOTED_selected">
<label for="post-ad_feature_NOT_PROMOTED_selected"><strong>I do not want to promote my ad</strong><span class="error"></span></label>

你好,

我在 Greasekit / Greasemonkey 上使用 Javascript,我想始终选中该框。(我不希望它影响同一页面上的其他复选框)(默认情况下该框始终未选中,当页面加载时,我想覆盖它)

谢谢

4

1 回答 1

5

对于您要查找的操作,您可以避免首先使用 JavaScript 并使用 HTMLchecked属性。

<div class="form-component form-checkbox">
<input id="post-ad_feature_NOT_PROMOTED_selected" checked="checked" type="checkbox" name="features['NOT_PROMOTED'].selected" value="true"   data-siblings="#post-ad_feature_URGENT_selected, #post-ad_feature_FEATURED_selected, #post-ad_feature_SPOTLIGHT_selected, #post-ad_feature_WEBSITE_URL_selected, #post-ad_feature_NOT_PROMOTED_selected" />
<label for="post-ad_feature_NOT_PROMOTED_selected"><strong>I do not want to promote my ad</strong><span class="error"></span></label>

如果您必须使用 JavaScript,那么您可以在加载页面后运行以下函数:

<script type="text/javascript">
function init()
{
    if(document.getElementById("post-ad_feature_NOT_PROMOTED_selected") != null)
    {
        document.getElementById("post-ad_feature_NOT_PROMOTED_selected").checked = true;
    }
}
</script>

...

<body onload="init();">
于 2013-04-26T12:53:50.060 回答