我有這種模式一堆形式:如果removeClass不影響源代碼,那有什麼意義?
<form action="/go/special" method="POST" target="_blank">
<input name="a" type="hidden" value="something"/>
<input type="submit" class="general effect" value="click me"></form>
對於具有special
其作用內部的各個形式,我想用這個jQuery代碼刪除effect
類:
<script src="/js/colorbox.js"></script>
<script>
jQuery(function($) {
// find all forms that have "special" in the action, find their input, and add the class
$('form[action*="special"] input[type="submit"]').removeClass('effect');
});
</script>
編輯:
effect
類代碼:
(jQuery, document, window), $(document).ready(function() {
$(".effect").click(function(t) {
t.preventDefault();
var e = $(this).closest("form");
return $.colorbox({
href: e.attr("action"),
transition: "elastic",
overlayClose: !1,
maxWidth: $("html").hasClass("ie7") ? "45%" : "false",
opacity: .8,
data: {
ago: e.find('input[name="a"]').val(),
}
}), !1
})
鏈接的彩盒代碼休息:
https://github.com/jackmoore/colorbox/blob/master/jquery.colorbox.js
的effect
類是Colorbox插件。如果存在,表單將在與模態窗口相同的窗口中打開。如果沒有,表格將在新標籤中打開。
該腳本刪除effect
類,但我可以看到只有當我檢查元素與我的控制檯它被移除。
然而,源代碼,沒有受到影響,而且還表明,它含有的類effect
。
因此,當我提交表單,它將使用顏色框插件,打開一個模式窗口,而不是新的選項卡。
是否有在第一時間使用removeClass
任何一點?
是否有任何變通辦法?
你是什麼意思'源代碼? – maowtm
Javascript在瀏覽器中運行,它修改了顯示的DOM。源代碼位於服務器上,瀏覽器無法更改。 – Barmar
源代碼是當頁面加載時運行JavaScript時最初加載的內容,並用您的更改更新DOM。 – Enjayy