কিভাবে copy, paste এবং cut behavior detect করা যায়? : জে-কোয়েরী -(পর্ব-২৯)

অনেক সময় application এর মধ্যে copy, paste এবং cut behavior detect করার প্রয়োজন হয়। যদিও এর জন্য অনেক সুন্দর সুন্দর tools রয়েছে যার মাধ্যমে effeciently client side এ অনেক behavior detect করা সম্ভব। নিচে এ সম্পর্কত একটি ছোট program দেয়া হল :

copy, pest এবং cut behavior detect করার জন্য অনুরূপ(corresponding) event গুলিকে bind করতে হবে :
[sourcecode language=”js”]
$("#textA").bind(‘copy’, function() {
$(‘span’).text(‘copy behaviour detected!’)
});
$("#textA").bind(‘paste’, function() {
$(‘span’).text(‘paste behaviour detected!’)
});
$("#textA").bind(‘cut’, function() {
$(‘span’).text(‘cut behaviour detected!’)
});
[/sourcecode]
আপনি যদি jQuery 1.4x use করে থাকেন তবে এটি নিচের মত multiple events declaration suppolrt করবে :
[sourcecode language=”js”]
$("#textA").bind({
copy : function(){
$(‘span’).text(‘copy behaviour detected!’);
},
paste : function(){
$(‘span’).text(‘paste behaviour detected!’);
},
cut : function(){
$(‘span’).text(‘cut behaviour detected!’);
}
});
[/sourcecode]

Try it yourself :

[sourcecode language=”html”]
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

<style type="text/css">
span{
color:blue;
}
</style>

</head>
<body>
<h1>jQuery copy, paste and cut example</h1>
<form action="#">
<label>TextBox : </label>
<input id="textA" type="text" size="50"
value="Copy, paste or cut message here" />
</form>

<span></span>

<script type="text/javascript">

$(document).ready(function() {

$("#textA").bind({
copy : function(){
$(‘span’).text(‘copy behaviour detected!’);
},
paste : function(){
$(‘span’).text(‘paste behaviour detected!’);
},
cut : function(){
$(‘span’).text(‘cut behaviour detected!’);
}
});

});
</script>
</body>
</html>
[/sourcecode]

Try Demo

………………………………………………………………………………
আলোকিত একটা সুন্দর সমৃদ্ধ পৃথিবী আমাদের প্রত্যেকেরই স্বপ্ন । আসুন আমাদের মেধা পরিশ্রম কে বিজ্ঞান সম্মতভাবে ব্যবহার করে, আমাদের স্বপ্ন পূরণে অংশ গ্রহণ করি। আজ এখানেই শেষ করলাম। “HAVE A GOOD PROGRAMMING”

জে-কোয়েরী ধারাবাহিক টিউটোরিয়ালঃ

Leave a Comment