将 document.getElementById 定位到子模板
Targeting document.getElementById to sub templates?
我无法解锁表单中的某些字段。我有一个 javascript 文件,它适用于某些页面,但不适用于其他页面。
我正在使用document.getElementById
来定位表单字段,以根据某些输入禁用或启用它们。它在一个页面上工作正常,但在另一个页面上不能。我已经仔细检查了我所有的ID,它们是正确的。这是javascript:
var pass2 = document.getElementById("password").value;
if (pass1 == pass2) {
//start profile
document.getElementById("premium-text").innerHTML = "Congratulations! You have unlocked the premium fields!";
document.getElementById("premium").style.background = "#d1fdd3";
document.getElementById("premium").style.borderColor = "#019408";
document.getElementById("description").disabled = false;
document.getElementById("fax-number").disabled = false;
document.getElementById("facebook-url").disabled = false;
document.getElementById("twitter-url").disabled = false;
document.getElementById("google-plus-url").disabled = false;
document.getElementById("linkedin-url").disabled = false;
document.getElementById("type").disabled = false;
document.getElementById("city").disabled = false;
document.getElementById("status").disabled = false;
document.getElementById("price").disabled = false;
document.getElementById("bedrooms").disabled = false;
document.getElementById("bathrooms").disabled = false;
document.getElementById("size").disabled = false;
document.getElementById("property-id").disabled = false;
document.getElementById("video-url").disabled = false;
document.getElementById("featured").disabled = false;
页面中唯一的区别是,一个页面在模板中具有表单字段(表单ID直接在edit-profile.php
中(,而另一个页面从包含ID的子模板中提取表单字段(submit-property.php
从子模板中提取表单字段partials/templates/submit-form.php
(。
我需要执行哪些操作来定位从子模板拉入的字段?id
被拉入页面源代码,所以我认为document.getElementById
可以正常工作,但不是出于某种原因。
javascript正在运行,但在此页面上不起作用。您必须创建一个帐户才能访问这些页面。用户test1
,传递testpass
。
解锁表单域的密码QuL7eD
确保您没有相同的多个 ID。如果你能发布你的代码,我将能够更好地帮助你。
我将Javascript分成两个单独的文件,这似乎有效。我只能假设这与每个页面上都有不同的字段 ID 这一事实有关,当 document.getElementById 运行时并且没有找到所有 ID(因为有些在不同的页面上(,这就是它不起作用的原因。
相关文章:
- CSS-如何定位内容数据标题
- 正在寻找比$(document).ready慢的$(window).load的替代方案
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 在Jquery detachment()和appendTo()之后定位元素
- 困在逻辑中试图定位动态的东西
- 如何用更合适的内容替换document.write
- document.styleSheets不返回任何内容
- jQuery document.ready not working
- $(document).height()在刷新时随机化值(Safari 5.1.10)
- reactjs this.refs vs document.getElementById
- 绝对定位不适用于Javascript DIV
- 如何通过adf中的document.getElementById获取inputText字段值
- Jquery定位代码并调用它
- window.opener.document在ie中不起作用
- 如何在容器中定位旋转的图像
- contentWindow.document.body is null
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- Highcharts-图表外的图例定位
- 将 document.getElementById 定位到子模板