0

这是 javascript -

  <script src='//www.google.com/jsapi' type='text/javascript'></script>
  <script type='text/javascript'>
  google.load('search', '1', {language: 'en', style: google.loader.themes.BUBBLEGUM});
  google.setOnLoadCallback(function() {
  var customSearchOptions = {};
  var orderByOptions = {};
  orderByOptions['keys'] = [{label: 'Relevance', key: ''} , {label: 'Date', key: 'date'}];
  customSearchOptions['enableOrderBy'] = true;
  customSearchOptions['orderByOptions'] = orderByOptions;
  var customSearchControl =   new google.search.CustomSearchControl('001216773833632189276:ki_enp2eefa', customSearchOptions);
  customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
  var options = new google.search.DrawOptions();
  options.setAutoComplete(true);
  customSearchControl.draw('cse', options);
  }, true);
  </script>

其返回的输入代码与表格列-

<td class="gsc-search-button"> <input type="button" value="Search" class="gsc-search-button" title="search"> </td>

在这里我想设置值GO。我怎么才能得到它 ?

4

3 回答 3

1
document.querySelector(".gsc-search-button").value = "GO";
于 2013-08-31T18:07:20.203 回答
1

如果您的页面中只有 1 个元素,请执行以下操作:

var searchField = document.getElementsByClassName("gsc-search-button")[0];
searchField.value = "GO";

示例:http: //jsfiddle.net/uN2NV/

对于多个元素试试这个:

var searchField = document.getElementsByClassName("gsc-search-button");
for(var i =0; i<searchField.length;i++)
{
    searchField[i].value = "GO";
}

示例:http: //jsfiddle.net/uN2NV/1/

对于共享同一类的多个元素中的不同元素:

var searchField = document.getElementById("distinct");
searchField.value = "GO";

示例:http: //jsfiddle.net/uN2NV/2/

于 2013-08-31T18:07:21.063 回答
0

如果你只想要那个元素,给它一个 ID

然后搜索它

var btn = document.getElementById("searchButton");

btn.value = "GO";

如果您知道这将是页面上具有此类的唯一项目,或者想要使用 gsc-search-button 类选择所有元素,那么其他答案之一将在不修改标记的情况下工作。

于 2013-08-31T18:07:00.127 回答