An electronic device includes a body, an input device and a connecting mechanism. The connecting mechanism includes a first connector and a second connector installed on the body and the input device, respectively. The connectors are connected via a magnetic interaction. When the electronic device approaches the input device, the electronic device is fixed on the input device by the magnetic interaction.