0

我从以前的项目中有这个 jQuery 代码,我想修改它:

<script>
...
$('a.manage-content-link').click(function (e) {
    var self = $(this),
        file = self.siblings('input[type="hidden.block-hidden-input"]').val();
    self.next(".manage-content-wrap").find(".manage-content").load("file-" + file + ".php");
    e.preventDefault();
});
...
</script>

这个 HTML 代码与之相关:

<li>
    <input type="hidden" name="block-type" value="0482" class="block-hidden-input" />
    <input type="hidden" name="sid" value="80132930913019309483" class="block-hidden-input" />
    <a href="#" id="manage-1" class="manage-content-link">
        <img src="images/web-block/web-block1.jpg"/>
        <span class="orange-notice">Click to Edit Content</span>    
    </a>
</li>

<li>
    <input type="hidden" name="block-type" value="1932" class="block-hidden-input" />
    <input type="hidden" name="sid" value="98u40190931209402191" class="block-hidden-input" />
    <a href="#" id="manage-2" class="manage-content-link">
        <img src="images/web-block/web-block2.jpg"/>
        <span class="orange-notice">Click to Edit Content</span> 
    </a>
</li>

我想将 jQuery LOAD 部分修改为如下所示:

.load("web-block/forms/file-XXX.php?key=YYYYYYYYYYYYYYYY");

在哪里 :

XXX = last 3 number from input type="hidden" name="block-type"
example :   0482 >> XXX = 482
            1932 >> XXX = 932

和 :

YYYYYYYYYYYYYYYY = 输入值 type="hidden" name="sid"

请注意,对于这个项目,我已经修改了 HTML 部分,因此它有 2 个隐藏的输入。所以我相信jQuery选择也需要修改......但是如何?

4

2 回答 2

1
$('a.manage-content-link').click(function (e) {
    var self = $(this),
        file = self.siblings('input[name="block-type"]').val();
    file = file.substring(file.length - 3);
    self.next(".manage-content-wrap").find(".manage-content").load("web-block/forms/file-" + file + ".php?key=" + self.siblings('input[name="sid"]').val());
    e.preventDefault();
});
于 2012-10-27T07:05:48.070 回答
1

e.preventDefault()在非匿名函数的开头使用

<li>
<input type="hidden" name="name-block-type" value="0482" class="block-hidden-input" />
<input type="hidden" name="name-sid" value="80132930913019309483" class="block-hidden-input" />
<a href="#" id="manage-1" class="manage-content-link">
    <span class="orange-notice">Click to Edit Content</span>    
</a>
</li>

<li>
<input type="hidden" name="name-block-type" value="1932" class="block-hidden-input" />
<input type="hidden" name="name-sid" value="98u40190931209402191" class="block-hidden-input" />
<a href="#" id="manage-2" class="manage-content-link">
    <span class="orange-notice">Click to Edit Content</span> 
</a>
</li>​

JS

$('a.manage-content-link').click(function (e) {
e.preventDefault();
var self = $(this),
    name = self.parent().find('input[name^=name]').val(),
    lastThree = file.substr(file.length - 3);
self.next(".manage-content-wrap").find(".manage-content").load("web-block/forms/file-" + lastThree + ".php");
});​
于 2012-10-27T07:07:30.257 回答