2017-08-17 27 views
0

传递值我有一个工作举表显示JSON数据,我对最后一列自定义的javascrip函数几个glyphicon。我可以成功获取javscript函数来执行mailto打开客户端本地邮件客户端以发送电子邮件,但是我希望能够将mailto函数中所选行的值传递给BOTH(主题字段和主体)。的Javascript的mailto从表上特定行

工作的mailto功能,当gylficon是单击列一表格

<script type="text/javascript"> 
        function actionFormatter(value, row, index) 
        { 
         return [       
          '<a class="edit ml10" href="javascript:void(0)" title="Edit">', 
          '<i class="glyphicon glyphicon-edit"></i>', 
          '</a>', 
          ' ', 
          '<a class="notifications ml10" href="javascript:void(0)" title="Notifications">', 
          '<i class="glyphicon glyphicon-send"></i>', 
          '</a>', 
          ' ', 
          '<a class="email ml10" href="javascript:void(0)" title="Email">', 
          '<i class="glyphicon glyphicon-envelope"></i>' 

         ].join(''); 
        } 
    window.actionEvents = { 
'click .email': function (e, value, row, index) { 
         $('.modalClick4').trigger('click'); 
         console.log(value, row, index); 

       // mailto code needs to go in here and passing the value of the specific row in the subject email  

        } 
       } 

我知道对于选择的行值正在按照控制台使用

<script> 

     function EmailSME() { 

     var email = '<"insert SME email Address">'; 
     var subject ='Sample text here'; 
     var emailBody = 'Hi Sample,'; 

     document.location = "mailto:"+email+"subject="+subject+"&body="+emailBody; 
     } 

    </script> 

的Java脚本函数。日志我可以确认值正在通过。

要注意,当我点击glyphicon“电子邮件”一物会触发一个模式,我则有3个按钮。第一个按钮是我试图在这里实现的mailto功能。在模态

<button onclick="EmailSME()" class="btn"> <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> 
      Email SME Template</button> 
+0

我相信你在'document.location'赋值中缺少'?'。 – logikal

回答

0

按钮,我相信你是从你document.location分配缺少?

尝试改变第一个脚本块:

<script> 

    function EmailSME() { 

    var email = '<"insert SME email Address">'; 
    var subject ='Sample text here'; 
    var emailBody = 'Hi Sample,'; 

    document.location = "mailto:"+email+"?subject="+subject+"&body="+emailBody; 
    } 

</script> 
+0

如何传递主题var中的行值? –

+0

这将设置受“示例文本在这里”(在'subject'变量的值),如果你想使用文本输入或别的东西,你需要与HTML中的ID创建的输入,然后使用' document.getElementByClassName('mySubjectField')。value' – logikal

0

你错过了?。 而你必须使用encodeURIComponent()函数。

<script> 

    function EmailSME() { 

    var email = '<"insert SME email Address">'; 
    var subject ='Sample text here'; 
    var emailBody = 'Hi Sample,'; 

    document.location = "mailto:"+encodeURIComponent(email)+"?subject="+encodeURIComponent(subject)+"&body="+encodeURIComponent(emailBody); 
    } 

</script> 
+0

即时尝试获取该行的值与我的电子邮件功能,但没有成功。我如何包含这个值?当我把这个我得到未定义的主题 var x = document.getElementsByName('').value; var subject ='此处示例文本'+ x; –

+0

@LetsTalkAboutIt你会得到哪个价值? –