尝试设置mailto:link

时间:2018-01-30 02:55:28

标签: javascript php html-email

我有一个网页,其中有一个表格可以插入供应商数据,一旦插入,公司名称就会被放入一个选择框中。选择公司时,将使用所有供应商信息调用表。

我的问题是 从php脚本调用vendor_email,是否有办法将id的值插入到mailto:function中。

 <tbody id="records">
    <td id="vendor_company"></td>
    <td id="vendor_rep"></td>
    <td id="vendor_email"></td>
</tbody>
<div class="row" id="no_records"><div class="col-sm-4">Plese select vendor name to view details</div></div>

这是我的php和js代码

<?php
include_once("Database/db_connect.php");
if($_REQUEST['empid']) {
$sql = "SELECT id, companyName, repName, venderEmail FROM vender_contact 
WHERE id='".$_REQUEST['empid']."'";
$resultset = mysqli_query($conn, $sql) or die("database error:". 
mysqli_error($conn));
$data = array();
while( $rows = mysqli_fetch_assoc($resultset) ) {
$data = $rows;
}
echo json_encode($data);
} else {
echo 0;
  }
 ?>

我的js代码

 $(document).ready(function(){
 // code to get all records from table via select box
 $("#vendors_data").change(function() {
 var id = $(this).find(":selected").val();
 var dataString = 'empid='+ id;

 $.ajax({
url:"getVendor.php",
dataType: "json",
data: dataString,
cache: false,
success: function(vendorData) {
if(vendorData) {
$("#heading").show();
$("#no_records").hide();
$("#vendor_company").text(vendorData.companyName);
$("#vendor_rep").text(vendorData.repName);
$("#vendor_email").text(vendorData.venderEmail);
$("#records").show();
} else {
$("#heading").hide();
$("#records").hide();
$("#no_records").show();
}
}
});
})
});

2 个答案:

答案 0 :(得分:2)

绝对可能!您只需使用 .html() 代替 .text()

请注意,mailto来自href属性,该属性对<a>标记而言是唯一的。因此,您希望将<a href=""></a>放在<td id="vendor_email"></td>内:

$("#vendor_email").html("<a href='mailto:" + vendorData.vendorEmail + "'>" + vendorData.vendorEmail + "</a>");

将呈现如下内容:

&#13;
&#13;
vendorData = {};
vendorData.vendorEmail = 'test@test.com';

$("#vendor_email").html("<a href='mailto:" + vendorData.vendorEmail + "'>" + vendorData.vendorEmail + "</a>");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="vendor_email"></div>
&#13;
&#13;
&#13;

除此之外,请注意您的MySQLi 易受攻击SQL injection。您应该使用prepared statements,并确保您的数据库用户只有required privileges以防止此情况发生。

您可以参考this post以获取有关如何在PHP中阻止SQL注入的更多信息:)

希望这有帮助!

答案 1 :(得分:0)

通过使用jQuery的.html()方法,您可以像这样插入html:

import java.util.List; import edu.cmu.lti.jawjaw.pobj.POS; import edu.cmu.lti.lexical_db.ILexicalDatabase; import edu.cmu.lti.lexical_db.NictWordNet; import edu.cmu.lti.lexical_db.data.Concept; import edu.cmu.lti.ws4j.Relatedness; import edu.cmu.lti.ws4j.RelatednessCalculator; import edu.cmu.lti.ws4j.impl.Lesk; import edu.cmu.lti.ws4j.util.WS4JConfiguration; public class LeskSimilarity{ public static void main(String[] args) { ILexicalDatabase db = new NictWordNet(); RelatednessCalculator lesk = new Lesk(db); String word1="rifle"; POS posWord1= POS.n; String word2= "gun"; POS posWord2= POS.n; double maxScore = 0; WS4JConfiguration.getInstance().setMFS(true); List<Concept> synsets1 = (List<Concept>)db.getAllConcepts(word1, posWord1.name()); List<Concept> synsets2 = (List<Concept>)db.getAllConcepts(word2, posWord2.name()); for(Concept synset1: synsets1) { for (Concept synset2: synsets2) { Relatedness relatedness = lesk.calcRelatednessOfSynset(synset1, synset2); double score = relatedness.getScore(); if (score > maxScore) { maxScore = score; } } } if (maxScore == -1D) { maxScore = 0.0; } System.out.println("Similarity score of " + word1 + " & " + word2 + " : " + maxScore); } }

顺便说一句,我无法帮助,但是注意到你已经将供应商拼写为#34; vender&#34;在$( '#vendor_email' ).html( '<a href="mailto:' + vendorData.vendorEmail + '">' + vendorData.vendorEmail + '</a>' );