【问题标题】:Send Feedback form发送反馈表
【发布时间】:2015-12-24 11:07:50
【问题描述】:

我有这个表格

对于星星,有 5 张图片的 onclick 设置为 functionstar1、functionstar2 等...改变了图片的 url(有 2 个 url star1.png(黄色)和 star2.png(白色))。这是控制星星的脚本:

<script>function functionStar1() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star0.png";
document.getElementById('star3').src = "star0.png";
document.getElementById('star4').src = "star0.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar2() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star0.png";
document.getElementById('star4').src = "star0.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar3() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star1.png";
document.getElementById('star4').src = "star0.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar4() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star1.png";
document.getElementById('star4').src = "star1.png";
document.getElementById('star5').src = "star0.png";
}
function functionStar5() {
document.getElementById('star1').src = "star1.png";
document.getElementById('star2').src = "star1.png";
document.getElementById('star3').src = "star1.png";
document.getElementById('star4').src = "star1.png";
document.getElementById('star5').src = "star1.png";
}</script>

我使用 javascript 发送信息,因为我需要使用此脚本的明星的网址:

<script>var password;
var titolo;
var feedback;
var valutazione;
var url;
function open(){
password = document.getElementById("password").value;
titolo = document.getElementById("titolo").value;
feedback = document.getElementById("feedback").value;
if (document.getElementById('star5').src == 'http://www.***.eu/star1.png') {
    valutazione = 'Eccellente';
} else if (document.getElementById('star4').src ==  
'http://www.***.eu/star1.png'){
    valutazione = 'Discreto';
}else if (document.getElementById('star3').src ==     
'http://www.***.eu/star1.png'){
    valutazione = 'Sufficiente';
}else if (document.getElementById('star2').src ==  
'http://www.***.eu/star1.png'){
    valutazione = 'Non sufficiente';
} else {
    valutazione = 'Pessimo';
}
url = 'http://www.***.eu/input.php?password=' + password + '&titolo=' +   
titolo + '&feedback=' + feedback + '&valutazione=' + valutazione;
document.getElementById("buttonhref").href = url;
}
setInterval(open, 10)</script>

问题在于它发送的&lt;textarea&gt; 文本没有\n。有没有办法使用 javascript 来获取带有 \n 的文本,或者更好的方法有没有办法在没有 javascript 的情况下发送星图的 url?

【问题讨论】:

标签: javascript php html


【解决方案1】:

如果您不想使用 Javascript 发送数据,您可以设置一个隐藏值,该值会根据星数进行更新,然后在提交表单后进行处理。

<input type="hidden" name="stars" value="5" id="stars-val" />

<script>
  function updateStarValue(starNum){ // star num is 1,2,3,4,5
  document.getElementByID("stars-val").val = starNum;
  }
</script>

然后在每个星星上,onclick=updateStarValue(2) 等等。

否则,使用 preg_replace 将换行符更改为

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 2011-09-30
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多