如何用js实现给某个文本框赋值?

JavaScript023

如何用js实现给某个文本框赋值?,第1张

用js实现给某个文本框赋值,可以先在js中获得文本框的元素,如

document.getElementsByName("result")[0]

然后把它的value属性赋值,如

document.getElementsByName("result")[0].value = 10

这是测试页面

其中

<input type="text" name="result" disabled="disabled">

这句中的disabled="disabled"就起到令文本框不可编辑变灰的效果。

这3行js代码的意思是,载入界面后,找到名称为result的元素,并给它赋值为10

window.onload = function(){

document.getElementsByName("result")[0].value = 10

}

ButtonClick: function (EntityName) {var testEntity = {} //主属性,名称字段,只能是单行文本testEntity.new_name = "通过代码新增的记录" //为单行文本字段赋值testEntity.new_SingleLine = "This account was created by the JavaScriptRESTDataOperations sample." //为两个选项字段赋值,只能赋值为true或者falsetestEntity.new_TwoOptionSet = true //为选项集字段赋值,为整数,是选项集的存储值,不是显示值testEntity.new_OptionSet = { Value: 100000001 } //为货币字段赋值testEntity.new_Currency = { Value: "20000.1" } //为浮点数字段赋值,小数即可testEntity.new_Float = 10.2 //为十进制字段赋值,特别注意要用引号引用起来testEntity.new_Decimal = "104.1" //为整数字段赋值testEntity.new_Integer = 200 //为日期和时间字段赋值testEntity.new_Datetime = new Date() //为多行文本字段赋值testEntity.new_MultiLine = "多行文本字段的值多行文本字段的值多行文本字段的值多行文本字段的值----多行文本字段的值" //为查找字段赋值testEntity.new_Lookup = { Id: "F3A0BB75-F3AD-E311-80B4-00155D016705", LogicalName: "account", Name: "随便什么值" } SDK.REST.createRecord(testEntity,"new_Test2013",function (TestEntity) {Xrm.Utility.alertDialog("新增记录成功,记录id是" + TestEntity.new_Test2013Id + "按确定按钮后将打开新增的记录",function () {Xrm.Utility.openEntityForm(EntityName, TestEntity.new_Test2013Id) }) },function errorHandler(error) {alert('Error message:' + error.message) }) }