2013-12-19 70 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