我有一个登录页面,我想要自定义它... 该页面是由其他代码创建的,所以我想用jquery自定义添加外部文件。 在这种情况下,我想在登录表单之前添加一个字符串,因此在标签之前,值为username ...
但是没有工作......
{{1}}
这是jsfiddle代码: http://jsfiddle.net/fw6nong1/2/
答案 0 :(得分:1)
您可以通过其属性选择标签。
var linkelimina = self.location.href;
$(document).ready(function () {
var link = self.location.href;
if (link == linkelimina || link == "http://www.webisite.com/user" || link == "http://www.website.com/user/password") {
$('.tabs').css('display', 'none');
$('.description').css('display', 'none');
$('label[for="edit-name"]').before('<h1>Effettua il login:</hi><br>');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="section"> <a id="main-content"></a>
<div class="tabs">
<h2 class="element-invisible">Primary tabs</h2>
<ul class="tabs primary">
<li><a href="/user/register">Create new account</a>
</li>
<li class="active"><a class="active" href="/user">Log in<span class="element-invisible">(active tab)</span></a>
</li>
<li><a href="/user/password">Request new password</a>
</li>
</ul>
</div>
<div class="region region-content">
<div class="block block-system" id="block-system-main">
<div class="content">
<form accept-charset="UTF-8" id="user-login" method="post" action="/user">
<div>
<div class="form-item form-type-textfield form-item-name">
<label for="edit-name">Username <span title="This field is required." class="form-required">*</span>
</label>
<input type="text" class="form-text required" maxlength="60" size="60" value="" name="name" id="edit-name">
<div class="description">Enter your website username.</div>
</div>
<div class="form-item form-type-password form-item-pass">
<label for="edit-pass">Password <span title="This field is required." class="form-required">*</span>
</label>
<input type="password" class="form-text required" maxlength="128" size="60" name="pass" id="edit-pass">
<div class="description">Enter the password that accompanies your username.</div>
</div>
<input type="hidden" value="form-l7DnfqR5ZJej8oGkHS8x_9YmAzOYnFX0qxiuSxY5XZI" name="form_build_id">
<input type="hidden" value="user_login" name="form_id">
<div id="edit-actions" class="form-actions form-wrapper">
<input type="submit" class="form-submit" value="Log in" name="op" id="edit-submit">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
答案 1 :(得分:1)
参见this JSFiddle:
我用
替换了你的代码$("label:contains('Username')").before('<h1>Effettua il login:</hi><br>');
修改强>
$("label[for='edit-name']").before('<h1>Effettua il login:</hi><br>');
也可以正常工作,只需将选择器替换为包含“Username *”
的标签的唯一选择答案 2 :(得分:0)
要按文字过滤,您可以使用:
$("label").filter(function(){
return $.trim($(this).text()) === "Username"; // trimming text because you have extra space
}).before('<h1>Effettua il login:</hi><br>');