我想通过使用此 js 代码通过 textarea 获取一些关键字。显然,我也需要 PHP 代码,但字符串 - 有问题var ehy = "php echo $dunno"
。为什么这个?谁能帮我?
<?php
if (isset($_POST['line'])) {
$line = $_POST['line'];
$dunno = (explode(" ", $line));
}
?>
<script>
function countLines(){
var stringLength = document.getElementById("myText").value.length;
var count = Math.ceil( stringLength / document.getElementById("myText").cols );
// just devide the absolute string length by the amount of horizontal place and ceil it
return count;
}
function what(){
var n = countLines()
var tarea = document.getElementById('myText')
var lines = tarea.value.split("\n")
//for(var x = 0; x < lines.length; x++) {
$.ajax({
type: "POST",
url: "",
data: "line="+lines,
success: function(){
var ehy = "<?php echo $dunno; ?>"
$('#what').text(ehy)
},
});
//}
}
</script>
</head>
<body>
<h1>SearchFunction()</h1>
<textarea rows="10" cols="70" id="myText"><?php echo "what the hell?";?></textarea>
<input type="button" onclick="what()"/>
<p id="try"></p>
<p id="what"></p>
</body>
</html>