如何将输入值传递给JavaScript函数?

时间:2013-03-27 20:21:17

标签: c# javascript html function

我有这段代码,并希望在点击图片时将输入传递给我的GoLargeSearch函数。

<div id="s4-searcharea-large">
    <input accessKey="S" onkeydown="CoreInvoke('LargeSearchKeyDownGoSearch', event)" id="txtLargeSearchTerm" runat="server" class="ms-sharepointsearchtext" title="Enter search words" value="" maxLength="255" size="25" type="text" name="SearchString" /> 
    <div class="ms-searchimage">
        <span style="position: relative; width: 27px; display: inline-block; height: 27px; overflow: hidden" class="s4-clust">
            <a style="width: 27px; display: inline-block; height: 27px" id="onetIDGoSearchLarge" title="Search" onclick="GoLargeSearch(document.getElementById('txtLargeSearchTerm'))" href="javascript:">
                <img style="border-bottom: 0px; position: absolute; border-left: 0px; border-top: 0px; border-right: 0px;" alt="Search" src="/_layouts/GP_Custom/images/largesearch.png" />
            </a>
        </span>
    </div>
</div>

如何获取输入值以将其传递给GoLargeSearch? 这似乎不起作用:

onclick="GoLargeSearch(document.getElementById('txtLargeSearchTerm'))"

2 个答案:

答案 0 :(得分:3)

您错过了获得该元素值的部分:

onclick="GoLargeSearch(document.getElementById('txtLargeSearchTerm').value)"

答案 1 :(得分:0)

这有效!

function GoLargeSearch (obj) { alert(obj.value); }

但这是非常难看的代码= / 你不能使用JQuery吗?