简体   繁体   English

如何从Java中的if语句在弹出屏幕中显示文本?

[英]How to display a text in a pop-up screen from an if statement in Javascript?

I would like to display what is in the texbox in the alert message below. 我想在下面的警报消息中显示texbox中的内容。

 alert("You have selected: " + cbotherstext);

 <input id="cbotherstext" type="text" /></td>

Thanks so much. 非常感谢。

Try this with jquery : 用jquery尝试一下:

 alert("You have selected: " + $("#cbotherstext").val());

 <input id="cbotherstext" type="text" />

you also need something that call the function eg (with Jquery) 您还需要一些调用该函数的东西,例如(使用Jquery)

<input id="cbotherstext" type="text" />
<a id="example">Example</a>
<script>
$("#example").click(function(){
    alert("You have selected: " + $("#cbotherstext").val());
});
</script>

Example with JQuery jQuery的示例

without Jquery 没有jQuery的

   <input type="text" id="cbotherstext" >
   <a onclick="alert_val()"> click me</a>
   <script> function alert_val(){
        alert("You have selected: " + document.getElementById('cbotherstext').value);
   }</script>

Without JQuery 没有JQuery

This is how to do it: 这是怎么做的:

 alert("You have selected: " + document.getElementById("cbotherstext").value);

 <input id="cbotherstext" type="text" /></td>

Try this 尝试这个

HTML 的HTML

 <input id="cbotherstext" type="text" />

Script 脚本

$("#cbotherstext").keyup(function(){
    alert("You have selected: " + $("#cbotherstext").val());
});

Fiddle 小提琴

http://jsfiddle.net/EQB68/ http://jsfiddle.net/EQB68/

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

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