如果标签包含与传递参数相同的值,我想禁用href和onclick事件,以下是我的脚本,但它禁用了与给定单词匹配的所有标记。
我想匹配精确的字符串并删除匹配时的href属性。
以下是我的代码:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("input[value *= '<?php echo($tag) ?>']").attr("disabled", "disabled");
$("a:contains('<?php echo($tag) ?>')").removeAttr("onclick");
$("a:contains('<?php echo($tag) ?>')").removeAttr("href");
//$( "div" ).not( ".green, #qm0" ).removeAttr("onclick");
//$( "div" ).not( ".green, #qm0" ).removeAttr("href");
});
</script>
答案 0 :(得分:1)
如果我正确理解了您的问题,您希望根据某些值过滤某些元素,并希望应用另一个过滤器将其从某个容器中排除。
Jquery Selector
$('a').not("#some_id a").filter(function(){
return (/string_to_be_matched/i).test($(this).text())
})// .any valid chain-able operation.
<强>解释强>:
$('a').not("#some_id a")
将为您提供DOM中的所有锚标记,但标识为some_id
的容器中的锚标记除外。
然后,您可以应用过滤器来匹配这些选定锚标记上的某些字符串值,
.filter(function(){
return (/string_to_be_matched/i).test($(this).text())
})
将string_to_be_matched
替换为您的字符串值。在你的情况下,也许有些php echo
PS:在应用上述选择器之前,请确保您的元素已添加到DOM 。 即使用$.ready或者如果您有静态内容,则脚本位于页面末尾。