简体   繁体   English

从没有表单的文本字段输入中获取值

[英]Get value from text field input without form

Im trying to send via ajax a value from a textfield, but don't want to use a form , don't think is needed: 我试图通过ajax从文本字段发送一个值,但不想使用表单,不要认为是需要的:

name = document.getElementByName["icall"].value;
alert( "Data Saved: " + name );
$.ajax({
type: "GET",
url: "ajaxload/icall.php",
data: "numero="+name
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});

This is the primary function, bellow is the html markup: 这是主要功能,下面是html标记:

<div class="conteudo">
            <span class="numero">O seu numero:</span><input type="text" name="icall" class="teximput" size="30"></input>
            <p><span class="avisome">Precisa de ajuda com algo? Nos ligamos consigo na proxima hora!</span></p>
            <a href="javascript:void(0)" onclick="ligarme();"><span class="botaoliga"></span></a>
        </div>

Shouldn't this be enough? 这不应该够吗?

Try: 尝试:

var name = $(".teximput").val();
$.ajax({
type: "GET",
url: "ajaxload/icall.php",
data: "numero="+name,
success:function(msg) {
alert( "Data Saved: " + msg );
});
document.getElementByName["icall"].value

is incorrect. 是不正确的。 The function is getElement s ByName. 该函数是getElement ByName。 Also, Instead of square brakets, use parentheses for function calls: 此外,使用括号进行函数调用,而不是方形的大括号:

document.getElementsByName("icall")[0].value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM