简体   繁体   English

php html输入文本字段

[英]php html input text field

The user sets through the field an inequality, ie 50<A, X>30, 50<C<100 . 用户通过该字段设置不等式,即50<A, X>30, 50<C<100 This is stored through javascript function on button click. 这是通过按钮点击的javascript功能存储的。

My issue is, the field doesn't work in a specific case when there's a "less than" symbol followed by a letter. 我的问题是,当字母后面有一个“小于”的符号时,该字段在特定情况下不起作用。 So, it will store fine eg X>30, A<50, but NOT 50<A or 50<C<100 . 因此,它将存储精细,例如X>30, A<50, but NOT 50<A or 50<C<100 In both of the latter cases it just shows the first number, meaning it's having trouble with the pattern "less than followed by letter", as this is simply omitted. 在后两种情况下,它只显示第一个数字,这意味着它的模式“少于后跟字母”有问题,因为这是简单的省略。 How do I make it work? 我如何使其工作?

Here's my code (php): 这是我的代码(php):

echo "<input type=\"text\" id=\"equation\">";
echo "<button onclick=\"addEq()\">Add</button>";

And javascript part (basically appends all equations entered, separated by ":") 和javascript部分(基本上附加所有输入的等式,用“:”分隔)

var addEq = function() {
    eq = document.getElementById("equation").value;
    if (document.getElementById("equation").innerHTML == "") {
        document.getElementById("equation").innerHTML = eq;}
    else {
        document.getElementById("equation").innerHTML += ":" + eq;}}

Replace the < in your inequalities with &lt; 用你的不等式替换< &lt; and > with &gt; >&gt; .
With < and a letter, the browser is trying to render it as html because it thinks it's a tag (like <a> ). 使用<和一个字母,浏览器会尝试将其呈现为html,因为它认为它是一个标记(如<a> )。

 var addEq = function() { eq = document.getElementById("equation").value.replace(/</g, '&lt;'); if (document.getElementById("result").innerHTML == "") { document.getElementById("result").innerHTML = eq; } else { document.getElementById("result").innerHTML += ":" + eq; } } function getResult() { var res = document.getElementById("result").innerHTML.replace(/&lt;/g, '<'); console.log(res); return res; } 
 <input type="text" id="equation" value="50<C<100"> <button onclick="addEq()">Add</button> <button onclick="getResult()">Result</button> <span id="result"></span> 

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

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