2013-12-19 72 views
0

我尝试了流星服务器给出了一个实例installation.In本例中一切都很好,但我有使用添加了一个新的输入field.How到在JavaScript中获得该输入文本值流星模板。我没有得到任何关于这个,所以请帮助我。获取HTML文本的输入值,使用JavaScript中的流星

HTML代码:

<head> 
    <title>myapp</title> 
</head> 

<body> 
    {{> hello}} 
</body> 

<template name="hello"> 
    <h1>Hello World!</h1> 
    {{greeting}} <br> 
    First name: <input type="text" name="firstname"><br> 
    <input type="button" value="Click" /> 
</template> 

JS代码:

if (Meteor.isClient) 
{ 
    Template.hello.greeting = function() 
    { 
    return "Welcome to myapp."; 
    }; 



    Template.hello.events 
    ({ 
    'click input' : function() 
    {  
     // template data, if any, is available in 'this' 
     if (typeof console !== 'undefined') 
     console.log("You pressed the button"); 
     alert("firstName="+ //here get input text value); 

    } 
    }); 
} 



if (Meteor.isServer) 
{ 
    Meteor.startup(function() 
    { 
    // code to run on server at startup 
    console.log("Is Running Server"); 
    }); 
} 
+0

这工作对我很好。您没有看到在js控制台中打印出“您按下了按钮”吗? –

+0

这也适用于我,没有理由不工作。 –

+0

真的,但是这不是me.so工作,我能做些什么错误?@去,奥列格 – Venkat

回答

0

客户端里面。你应该返回false

Template.hello.events 
    ({ 
    'click input' : function() 
    {  
     console.log("You pressed the button"); 
     return false; 

    } 
    }); 
+0

这也不会被执行@pahan。 – Venkat

+0

@Venkat这个工作。也许你没有看javascript控制台。如果您希望将console.log作为消息框,请将'console.log'更改为'alert' – Akshat