打印变量到输入字段元素

时间:2015-08-16 15:09:29

标签: javascript

您好我有这个输入,我想知道如何根据它的ID打印一个值?

<input name="field[34]" id="field34" class="input-text required-entry validate-field-hint-34 webforms-fields-hint" style="" value="E.g: NX15 NAM" onfocus="if (this.value == 'E.g: NX15 NAM') {this.value = ''; $(this).removeClassName('webforms-fields-hint');}" onblur="if (this.value == '') {this.value = 'E.g: NX15 NAM'; $(this).addClassName('webforms-fields-hint');}" type="text">

我有这个脚本,它接受URL的值并将其转换为变量。我现在想将此变量打印到输入字段。

var QueryString = function () {
  // This function is anonymous, is executed immediately and 
  // the return value is assigned to QueryString!
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
        // If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = decodeURIComponent(pair[1]);
        // If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
      query_string[pair[0]] = arr;
        // If third or later entry with this name
    } else {
      query_string[pair[0]].push(decodeURIComponent(pair[1]));
    }
  } 
    return query_string;
}();

知道我该怎么做吗?

谢谢,尼克

0 个答案:

没有答案