我正在尝试通过使用用户输入和 JS 来更轻松地将作弊码转换为 HTML 格式。
例如,以下代码应将 R1、R1、CIRCLE、R2、LEFT、RIGHT、LEFT、RIGHT、LEFT、RIGHT 转换为
<div class="ps3 r1"></div>
<div class="ps3 r1"></div>
<div class="ps3 circle"></div>
<div class="ps3 r2"></div>
<div class="ps3 left"></div>
<div class="ps3 right"></div>
<div class="ps3 left"></div>
<div class="ps3 right"></div>
<div class="ps3 left"></div>
<div class="ps3 right"></div>
但返回替换逗号的输入,而不是按钮组合。任何其他方法/帮助将不胜感激!控制台为空,没有出现错误。
JS
$('.submit').click(function() {
var raw = $('#raw').val();
var st1 = raw.replace(/,/g , "");
var st2 = st1.replace(/l1/g , "<div class='ps3 l1'></div>");
var st3 = st2.replace(/l2/g , "<div class='ps3 l2'></div>");
var st4 = st3.replace(/square/g , "<div class='ps3 square'></div>");
var st5 = st4.replace(/circle/g , "<div class='ps3 circle'></div>");
var st6 = st5.replace(/triangle/g , "<div class='ps3 triangle'></div>");
var st7 = st6.replace(/x/g , "<div class='ps3 cross'></div>");
var st8 = st7.replace(/r1/g , "<div class='ps3 r1'></div>");
var st9 = st8.replace(/r2/g , "<div class='ps3 r2'></div>");
var st10 = st9.replace(/right/g , "<div class='ps3 right'></div>");
var st11 = st10.replace(/left/g , "<div class='ps3 left'></div>");
$('.result').html(st11);
});
HTML
<input id="raw" type="text">
<button class="submit">Generate</button>
<div class="result"></div>