[英]Autofill input text on Sharepoint 2007 using Jquery
im sure this is a simple question but can't understand why this isn't working. 我肯定这是一个简单的问题,但不明白为什么这不起作用。 I simply want to set the current time automatically to an input field.
我只是想将当前时间自动设置为输入字段。 I am using Jquery at the moment to accomplish the task.
我目前正在使用Jquery完成任务。 I know jquery works because if I do alert (time);
我知道jQuery的工作原理是因为如果我发出警报(时间); it shows me the time as expected.
它显示了我所期望的时间。
Just to add, I set the jquery script in a text then referenced into a Content Editor Webpart under the list. 只是要添加,我将jquery脚本设置为文本,然后将其引用到列表下的Content Editor Webpart中。
Below is the HTML of my input generated by Sharepoint. 以下是Sharepoint生成的我的输入的HTML。 I decided to target the title as its the only consisting attribute in there.
我决定将标题作为那里唯一包含的属性。
<input type="text" class="ms-long" title="Current time" id="ctl00_m_g_dd7a368d_cc10_4464_a245_c7fc87ae6650_ff2_1_ctl00_ctl00_TextField" maxlength="255" name="ctl00$m$g_dd7a368d_cc10_4464_a245_c7fc87ae6650$ff2_1$ctl00$ctl00$TextField">
Below is the Jquery script I am trying to run. 以下是我尝试运行的Jquery脚本。 A the moment this script does nothing to my input text box.
此刻此脚本对我的输入文本框不起作用。
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
var time = (dNow.getMonth()+1) + '/' + dNow.getDate() + '/' + dNow.getFullYear() + ' ' + dNow.getHours() + ':' + dNow.getMinutes();
$("input[Title='Current time']").val(time);
});
</script>
Any help would appreciated on this. 任何帮助将不胜感激。
I tested your code and it works fine if you define the dNow first: tested on Chrome and Opera 我测试了您的代码,如果您先定义dNow,它就可以正常工作:已在Chrome和Opera上测试
jQuery(document).ready(function($) {
var dNow = new Date();
var time = (dNow.getMonth()+1) + '/' + dNow.getDate() + '/' + dNow.getFullYear() + ' ' + dNow.getHours() + ':' + dNow.getMinutes();
alert(time);
$("input[title='Current time']").val(time);
});
If that's not working for you, you have some other problem in your JavaScript, debug and check for other errors 如果这对您不起作用,则您的JavaScript中还有其他问题,请调试并检查其他错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.