将文本框值转换为int [英] Converting text box value to int

查看:158
本文介绍了将文本框值转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试应用在Google和Stackoverflow上都可以找到的解决方案,但是它们似乎没有用.

I have been trying to apply solutions I found on both Google and Stackoverflow, but they don't seem to be working.

这里到底出了什么问题?此处的复选框微不足道,我可以将其删除,但这没什么区别.

What exactly is going wrong here? The checkbox is insignificant here and I can take it out, but it makes no difference.

<div class="form-group">
    <label for="tbid" class="col-lg-3 control-label">Results per page </label>
        <div class="col-lg-3">
            <input type="checkbox" class="checkbox" display="inline-block" name="checkbox_results" onclick="checkbox_results_click();">
            <input type="text" id="results" class="form-control" name="results" placeholder="results">
        </div>
</div>

然后在js部分中,我试图将结果转换为int.

Then in the js portion, I am trying to convert results into an int.

<script type="text/javascript">
    int results = null;
    var x=document.getElementById("results").value;

    results = parseInt(x);
    if(results==null)
        results=10;

    var pager = new Pager(results);

</script>

我还应该补充一点,如果我只是在调用pager时放一个int参数,例如25,它实际上就可以了.所以结果出了点问题.

I should also add that if I just put a int parameter when calling pager, like 25, for example, it actually works. So something is going wrong with results.

推荐答案

代替使用parseInt使用parseFloat,它将像这样

Instead of using parseInt use parseFloat it will work like this

results = parseFloat(x);

这篇关于将文本框值转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆