在JavaScript中我想提出的myArray
有條件的內容(如果statment我猜使用。我已經試過這樣做,但都無濟於事。我想作一個JavaScript數組條件
我的一些代碼供參考:
<?php
session_start();
$theirname = $_GET['theirname'];
$yourname = $_GET['yourname'];
$slct2 = $_GET['slct2'];
$slct1 = $_GET['slct1'];
?>
<script type="text/javascript">
var theirName = "<?php echo $theirname; ?>";
var yourName = "<?php echo $yourname; ?>";
var cardType = "<?php echo $slct1; ?>";
var personType = "<?php echo $slct2; ?>";
var myArray=[
"i need",
"to make the contents of ",
"this array",
"conditional",
"to the variable",
"cardType",
"and the variable",
"personType",
];
//shuffle array:
myArray.sort(function(){return Math.round(Math.random());});
//print to screen
function printGreet(){
document.getElementById('demo').innerHTML= [myArray.pop()];
}
</script>
<div>
<button onclick="printGreet()" class="large-btn" id="generate-Btn" rows="20">Generate</button>
</div>
<div id="yourMes">
<p>Your message:</p>
</div>
<textarea name="text1" class="large-fld" id="demo"></textarea>
你所說的「條件變量」是什麼意思? – Kyo
@Kyo卡類型的變量,對不起。例如if(cardType ==「birthday」){then do this} – Acendor